#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=1e5+10;
char a[MAXN];
int n,m,rk[MAXN],sa[MAXN],height[MAXN],f[MAXN][20];
LL ans1,ans2;
struct temp
{
	int num,x,y;
	bool operator<(const temp b)const
	{
		return x==b.x?y<b.y:x<b.x;
	}
}tmp[MAXN];
void cal_rk()
{
	for(int i=0;(1<<i)<=n;++i)
	{
		memset(tmp,0,sizeof(tmp));
		for(int j=1;j<=n;++j)
		{
			tmp[j].num=j;
			tmp[j].x=rk[j];
			if(j+(1<<i)<=n)tmp[j].y=rk[j+(1<<i)];
		}
		sort(tmp+1,tmp+1+n);
		int cnt=0;
		for(int j=1;j<=n;++j)
		{
			if(tmp[j].x!=tmp[j-1].x||tmp[j].y!=tmp[j-1].y)++cnt;
			rk[tmp[j].num]=cnt;
		}
	}
	return;
}
void cal_sa()
{
	for(int i=1;i<=n;++i)
		sa[rk[i]]=i;
	return;
}
void cal_height()
{
	int j,k=0;
	for(int i=1;i<=n;++i)
	{
		if(k)--k;
		j=sa[rk[i]-1];
		while(a[i+k]==a[j+k])++k;
		height[rk[i]]=k;
	}
	return;
}
void cal_ST()
{
	for(int i=1;i<=n;++i)f[i][0]=height[i];
	for(int i=1;(1<<i)<=n;++i)
		for(int j=1;j+(1<<(i-1))<=n;++j)
			f[j][i]=min(f[j][i-1],f[j+(1<<(i-1))][i-1]);
	return;
}
int query(int l,int r)
{
	if(l>r)swap(l,r);
	++l;
	int k=0;
	while((1<<(k+1))<=r-l+1)++k;
	return min(f[l][k],f[r-(1<<k)+1][k]);
}
int cal_bit(int a)
{
	if(a<10)return 1;
	if(a<100)return 2;
	if(a<1000)return 3;
	if(a<10000)return 4;
	if(a<100000)return 5;
}
int main()
{
	while(scanf("%s",a+1)!=EOF)
	{
		ans1=ans2=0;
		n=strlen(a+1);
		for(int i=1;i<=n;++i)rk[i]=a[i]-'a'+1;
		cal_rk();
		cal_sa();
		cal_height();
		cal_ST();
		scanf("%d",&m);
		--m;
		int last1,last2,l,r;
		scanf("%d%d",&l,&r);
		++l;
		last1=l;
		ans1=ans2=last2=r-l+1;
		ans2+=3;
		++ans1;
		while(m--)
		{
			scanf("%d%d",&l,&r);
			++l;
			ans1+=r-l+2;
			ans2+=2;
			int t=l==last1?last2:query(rk[l],rk[last1]);
			t=min(t,min(last2,r-l+1));
			ans2+=cal_bit(t)+r-l+1-t;
			last1=l;
			last2=r-l+1;
		}
		printf("%I64d %I64d\n",ans1,ans2);
	}
	return 0;
}
